﻿using System.Collections.Generic;
using LLoger;
using LimitatorInterfaces.LoadServices;


namespace LimitatorInterfaces
{
    public class LoadService : ServiceBase, ILoadService
    {
        private readonly ILoadProvider _loadProvider;
        private readonly ILoadParser _loadParser;
        private readonly string _configPath;

        public LoadService(ILoadProvider loadProvider, ILoadParser loadParser, string configPath, ILogWriter logWriter, Dictionary<string, object> args = null)
            : base(configPath, logWriter, args)
        {
            _loadProvider = loadProvider;
            _loadParser = loadParser;
            _configPath = configPath;
           
        }

        public void LoadLimits(List<LimitEntity> limitsTable)
        {
            object limFile =  GetStartWithSettingValues(LoadServiceRes.LoadProviderParam);
            
            object[] fromFile = _loadProvider.LoadFromSource(limFile);

            foreach (var s in fromFile)
            {
                limitsTable.Add(_loadParser.ParceFrom(s));
            }

            LogWriter.WriteLine("Всего исходных лимитов: " + limitsTable.Count);
        }
    }
}